﻿using System;

using System.Collections.Generic;
using System.Text;
using Silvermoon.Utils;
using System.Drawing;
using Silvermoon.OpenGL;

namespace Silvermoon.Shapes
{
    public static class ColorArrays
    {
        public static int[] Create4QuadArray(Color color, int alpha, RenderStyle style)
        {
            Color[] colors = GetColors(style, color);
            
            int[] colorArray = new int[16];
            colorArray[0] = colorArray[1] = colorArray[4] = colorArray[5] = ColorUtil.AlphaSwapBRColor(colors[0], alpha).ToArgb();
            colorArray[2] = colorArray[3] = colorArray[6] = colorArray[7] = ColorUtil.AlphaSwapBRColor(colors[1], alpha).ToArgb();
            colorArray[8] = colorArray[9] = colorArray[12] = colorArray[13] = ColorUtil.AlphaSwapBRColor(colors[2], alpha).ToArgb();
            colorArray[10] = colorArray[11] = colorArray[14] = colorArray[15] = ColorUtil.AlphaSwapBRColor(colors[3], alpha).ToArgb();

            //if (beveled)
            //{
            //    // this would be a 3d effect:
            //    colorArray[3] = colorArray[6] = colorArray[0];
            //    colorArray[9] = colorArray[12] = colorArray[10];
            //}
            return colorArray;
        }

        public static Color[] GetColors(RenderStyle style, Color color)
        {
            Color[] colors;

            switch (style)
            {
                case RenderStyle.Plastic:
                    colors = ColorUtil.CreatePlasticColors(color);
                    break;

                case RenderStyle.FlatChrome:
                    colors = ColorUtil.CreateFlatChromeColors(color);
                    break;

                case RenderStyle.Gradiented:
                    colors = ColorUtil.CreateGradientColor(color);
                    break;

                default:
                    throw new NotImplementedException();
            }
            return colors;
        }

        public static int[] Create6QuadArray(Color color, int alpha, Texture texture, int height)
        {
            Color[] colors = ColorUtil.CreateChromeColors(color);

            int h = height; if (h == 0) h = int.MaxValue;
            int scale = texture != null ? 256 * texture.StorageSize.Height / h : 128;
            Color c1 = ColorUtil.InterpolateColor(colors[0], colors[1], scale);
            Color c2 = ColorUtil.InterpolateColor(colors[3], colors[2], scale);
            int[] colorArray = new int[24];
            colorArray[0] = colorArray[1] = colorArray[2] = colorArray[3] = ColorUtil.AlphaSwapBRColor(colors[0], alpha).ToArgb();
            colorArray[4] = colorArray[5] = colorArray[6] = colorArray[7] = ColorUtil.AlphaSwapBRColor(c1, alpha).ToArgb();
            colorArray[8] = colorArray[9] = colorArray[10] = colorArray[11] = ColorUtil.AlphaSwapBRColor(colors[1], alpha).ToArgb();
            colorArray[12] = colorArray[13] = colorArray[14] = colorArray[15] = ColorUtil.AlphaSwapBRColor(colors[2], alpha).ToArgb();
            colorArray[16] = colorArray[17] = colorArray[18] = colorArray[19] = ColorUtil.AlphaSwapBRColor(c2, alpha).ToArgb();
            colorArray[20] = colorArray[21] = colorArray[22] = colorArray[23] = ColorUtil.AlphaSwapBRColor(colors[3], alpha).ToArgb();
            return colorArray;
        }

    }
}
